// 放大镜
function $(id) {
    return document.getElementById(id);
  }
  class Zoom {
    constructor() {
      this.box = $("box");
      this.middle = $("middle");
      this.midimg = this.middle.children[0];
      this.zoom = $("zoom");
      this.big = $("big");
      this.bigimg = this.big.children[0];
      this.small = $("small");
      this.smaimg = this.small.children;
      this.move();
    }
    
    move() {
      this.middle.onmouseover = () => {
        this.zoom.style.display = "block";
        this.big.style.display = "block";
      };
      this.middle.onmouseout = () => {
        this.zoom.style.display = "none";
        this.big.style.display = "none";
      };
      this.middle.onmousemove = (e) => {
        let evt = e || event;
        let l = evt.pageX - this.box.offsetLeft - this.zoom.offsetWidth / 2;
        let t = evt.pageY - this.box.offsetTop - this.zoom.offsetHeight / 2;
        if (l <= 0) {
          l = 0;
        }
        if (l >= this.middle.offsetWidth - this.zoom.offsetWidth) {
          l = this.middle.offsetWidth - this.zoom.offsetWidth;
        }
        if (t <= 0) {
          t = 0;
        }
        if (t >= this.middle.offsetHeight - this.zoom.offsetHeight) {
          t = this.middle.offsetHeight - this.zoom.offsetHeight;
        }

        this.zoom.style.left = l + "px";
        this.zoom.style.top = t + "px";
        this.bigimg.style.left = -2 * l + "px";
        this.bigimg.style.top = -2 * t + "px";
      };
      for (let i = 0; i < this.smaimg.length; i++) {
        this.smaimg[i].onmouseover = () => {
          this.midimg.src = this.bigimg.src = this.smaimg[i].src;
        };
      }
    }
  }
  new Zoom();

  function setCookie(key, value, expires) {
    if (expires) {
        let oDate = new Date();
        oDate.setDate(oDate.getDate() + expires);
        document.cookie = `${key}=${value};expires=${oDate}`;
      } else {
        document.cookie = `${key}=${value}`;
      }
  }


  function getCookie(key) {
    let str = document.cookie;
    let arr = str.split(";");
    let value;
    /* str.forEach(item => {
      // console.log(item);
      let arr = item.split('=');
      if(arr[0] == "key"){
        value = arr[1]
      }
    });
    return value; */
    for (let i = 0; i < arr.length; i++) {
      let brr = arr[i].split("=");
      if (brr[0] === key) {
        return brr[1];
      }
    }
  }

  
  function removeCookie(key) {
    setCookie(key, 1, -1);
  }

  let pid = getCookie("pid")
        console.log(pid);

        $.get("http://jx.xuzhixiang.top/ap/api/allproductlist.php", {
            pagesize: 1,
            pagenum: 0,
            uid: 139171,
          }).then((resData) => {
            console.log(resData.data);
          });

          




